//---------------------------------------------------------------------------


#pragma hdrstop

#include "stdafx.h"
#include "ComponentConfiguration.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

TYbCommDevice *Comm_UB;
TYbCommDevice *Comm_RL;
TYbCommDevice *Comm_LL;
TYbCommDevice *Comm_Comp;
TYbCommDevice *Comm_HMI;
TYbCommDevice *Comm_ControlBoard;

//Comm_Comp->
//Comm_HMI->
//Comm_ControlBoard->
unsigned char CommBuff[COMM_BUFF_SIZE] = {0};

void Comm_Init(void)
{
	Comm_UB = new TYbCommDevice(FormMotionControl);
	Comm_RL = new TYbCommDevice(FormMotionControl);
	Comm_LL = new TYbCommDevice(FormMotionControl);
	Comm_Comp = new TYbCommDevice(FormMotionControl);
	Comm_HMI = new TYbCommDevice(FormMotionControl);
	Comm_ControlBoard = new TYbCommDevice(FormMotionControl);

//	Comm_UB->PortNo = 17;
//	Comm_RL->PortNo = 4;
//	Comm_LL->PortNo = 5;
//	Comm_Comp->PortNo = 6;
//	Comm_HMI->PortNo = 7;
//	Comm_ControlBoard->PortNo = 8;

	Comm_UB->Baud = BAUDRATE;
	Comm_RL->Baud = BAUDRATE;
	Comm_LL->Baud = BAUDRATE;
	Comm_Comp->Baud = BAUDRATE;
	Comm_HMI->Baud = BAUDRATE;
	Comm_ControlBoard->Baud = BAUDRATE;

//	MOTOR_LL_PORT->Active = true;
}

void Comm_Write(TYbCommDevice *commport, unsigned char *address, int num)
{
	if(commport->Active == true)
	{
		commport->OutQueue->Clear();
		commport->Write(address, num);
	}
}

//int Comm_Read(TYbCommDevice *commport, unsigned char *inbuff)
//{
//	DWORD nBytesRead, dwEvent, dwError;
//	COMSTAT cs;
//	HANDLE hComm = commport->Handle;
//
//	ClearCommError(hComm,&dwEvent,&cs);
//
//	if(cs.cbInQue > COMM_BUFF_SIZE)
//	{
//		PurgeComm(hComm, PURGE_RXCLEAR);
//		return -1;
//	}
//	ReadFile(hComm, inbuff, cs.cbInQue, &nBytesRead, NULL);
//	return ((int)cs.cbInQue);
//}
